<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="wechat-enable-text-zoom-em" content="true">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="color-scheme" content="light dark">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
	<link rel="shortcut icon" type="image/x-icon" href="//res.wx.qq.com/a/wx_fed/assets/res/NTI4MWU5.ico" reportloaderror>
	<link rel="mask-icon" href="//res.wx.qq.com/a/wx_fed/assets/res/MjliNWVm.svg" color="#4C4C4C" reportloaderror>
	<link rel="apple-touch-icon-precomposed" href="//res.wx.qq.com/a/wx_fed/assets/res/OTE0YTAw.png" reportloaderror>
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<meta name="referrer" content="origin-when-cross-origin">
	<meta name="referrer" content="strict-origin-when-cross-origin">
	<meta name="description" content="">
	<meta property="og:title" content="">
    <meta property="og:description" content="">
    <!--分享卡片图标，可以自己换-->
    <meta property="og:image" content="https://img.pddpic.com/mms-material-img/2023-12-14/08d321d2-77ac-4cbf-ac16-8456891f1546.jpeg.a.jpeg">
	<style>
	    *{
	        padding: 0;
	        margin: 0;
	    }
	    
	    /*背景图*/
	    body {
	        position: fixed;
	        top: 0;
	        width: 100%;
	        height: 100%;
	    }
	    
	    /* 遮罩层样式 */
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
            z-index: 1;
        }

        /* 模态框样式 */
        .alertModal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            padding: 30px;
            z-index: 2;
            border-radius: 10px;
            width: 60%;
        }
        
        /*模态框标题*/
        .alertModal .h3-title{
            color: #ee4234;
            text-align: center;
            margin-bottom: 20px;
        }
        
        /*模态框文字*/
        .alertModal p{
            font-size: 16px;
            line-height: 30px;
            text-align: center;
        }
	   
	</style>
</head>
<body id="myBody">
    
    <!-- 模态框遮罩层 -->
    <div id="modalOverlay" class="modal-overlay"></div>

    <!-- 模态框 -->
    <div id="myModal" class="alertModal">
        <h3 class="h3-title">红包码复制成功</h3>
        <p>1. 打开支付宝APP</p>
        <p>2. 粘贴至搜索框</p>
        <p>3. 点击下方搜索领取</p>
        <p> - - - </p>
        <p>或者尝试一下</p>
        <p> 👇︎👇︎👇︎ </p>
        <p>右上角[···]在浏览器打开可直接跳到支付宝APP自动领取</p>
    </div>
	
	<script type="text/javascript">
	
	    // 创建一个XHR对象获取支付宝赏金红包的配置信息
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '../../console/plugin/app/alipayShangJin/server/alipayShangJin.json', true);
        xhr.onload = function () {
          if (xhr.status >= 200 && xhr.status < 300) {
              
            // 请求成功，处理响应数据
            var alipayShangJinData = JSON.parse(xhr.responseText);
            
            // 标题
            document.title = alipayShangJinData.alipayShangJinSPA_title;
            
            // 摘要
            document.querySelector('meta[name="description"]').setAttribute('content', alipayShangJinData.alipayShangJinSPA_desc);
            
            // 设置分享卡片的标题和摘要
            var ogTitleMeta = document.querySelector('meta[property="og:title"]');
            var ogDescMeta = document.querySelector('meta[property="og:description"]');
            ogTitleMeta.setAttribute('content', alipayShangJinData.alipayShangJinSPA_title);
            ogDescMeta.setAttribute('content', alipayShangJinData.alipayShangJinSPA_desc);
            
            // 支付宝商家ID
    		var shareId = alipayShangJinData.alipayShangJinSPA_uid;
    
    		// 红包码Token
    		var toKen = alipayShangJinData.alipayShangJinSPA_token;
    		
    		// 红包码搜索码
    		var hongbaoNum = alipayShangJinData.alipayShangJinSPA_hbm;
    		
            // 背景图
            var bgIMG = alipayShangJinData.alipayShangJinSPA_bgImg;
            
            // 设备判断
            detectMobileOperatingSystem(shareId, toKen, hongbaoNum, bgIMG);
            
            // 禁止页面上下滑动
            disableScroll();
            
            
          } else {
              
            // 请求失败，处理错误
            console.error('请求失败，状态码:', xhr.status);
          }
        };
        xhr.onerror = function () {
          console.error('请求发生错误');
        };
        xhr.send();
		
		// 跳转
		function jumpToAlipayApp(shareId, toKen) {

			window.location.href = 'https://ulink.alipay.com/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FsaId%3D10000007%26clientVersion%3D3.7.0.0718%26qrcode%3Dhttps%253A%252F%252Frender.alipay.com%252Fp%252Fc%252Falipay-red-qrcode%252Fshared.html%253Fchannel%253Dsearch_pwd%2526shareId%253D' + shareId + '%2526token%253D' + toKen + '%2526campStr%253DkPPFvOxaCL3f85TiKss2wsBZgIjulHjG%2526sign%253DqsiVOoa7TuphryWxyBdONXsMTnE3jiIBvWeUs3yV1sw%253D%2526chInfo%253DDingtalk%2526c_stype%253Dsearch_pwd';
		}

		// 设备判断
		function detectMobileOperatingSystem(shareId, toKen, hongbaoNum, bgIMG) {

		    const userAgent = navigator.userAgent;
		    if (/Android/i.test(userAgent)) {

		    	// Android
                var body = document.querySelector('body');
                body.style.background = "url('"+ bgIMG +"') no-repeat";
                body.style.backgroundSize = "100%";
                
                // 如果不是在微信内打开
                if (navigator.userAgent.indexOf("MicroMessenger") !== -1) {
                    
                    // 微信浏览器
                    // 获取<body>标签
                    var body = document.getElementById("myBody");
                    
                    // 监听body的点击
                    body.addEventListener("click", function() {
                        
                        // 复制红包码
                        copyToClipboard(hongbaoNum);
                    });
                }else {
                    
                    // 非微信浏览器
                    // 尝试跳转
                    jumpToAlipayApp(shareId, toKen);
                }
		    } else if (/iPhone|iPad|iPod/i.test(userAgent)) {

		    	// iOS
                var body = document.querySelector('body');
                body.style.background = "url('"+ bgIMG +"') no-repeat";
                body.style.backgroundSize = "100%";
                
		        // 获取<body>标签
                var body = document.getElementById("myBody");
                
                // 自动跳
                jumpToAlipayApp(shareId, toKen);
            
                // 监听body的点击
                body.addEventListener("click", function() {
                    
                    // 跳转到支付宝APP
                    jumpToAlipayApp(shareId, toKen);
                });
		    } else {

		    	// 未知操作系统
                var elementToModify = document.querySelector('body');
                elementToModify.style.background = "url('"+bgIMG+"') no-repeat";
                elementToModify.style.backgroundSize = "100%";
                
                // 如果不是在微信内打开
                if (navigator.userAgent.indexOf("MicroMessenger") !== -1) {
                    
                    // 微信浏览器
                    // 获取<body>标签
                    var body = document.getElementById("myBody");
                    
                    // 监听body的点击
                    body.addEventListener("click", function() {
                        
                        // 复制红包码
                        copyToClipboard(hongbaoNum);
                    });
                }else {
                    
                    // 非微信浏览器
                    // 尝试跳转
                    jumpToAlipayApp(shareId, toKen);
                }
		    }
		}
		
        // 禁止页面上下滑动
		function disableScroll() {
		    
            document.addEventListener("touchmove", function(e) {
                e.preventDefault();
            }, { passive: false });
        }
        
        // 打开模态框
        function openModal() {
            document.getElementById("modalOverlay").style.display = "block";
            document.getElementById("myModal").style.display = "block";
        }
    
        // 关闭模态框
        function closeModal() {
            document.getElementById("modalOverlay").style.display = "none";
            document.getElementById("myModal").style.display = "none";
        }
        
        // 复制红包码
        function copyToClipboard(textToCopy) {
            
            // 创建一个临时文本框元素
            const tempInput = document.createElement("input");
            tempInput.value = textToCopy;
            document.body.appendChild(tempInput);
            
            // 选择文本框的内容
            tempInput.select();
            
            // 尝试复制文本到剪贴板
            document.execCommand("copy");
            
            // 移除临时文本框元素
            document.body.removeChild(tempInput);
            
            // 复制完成，打开弹窗
            openModal();
        }
	</script>
</body>
</html>